/********************************************************************
	Rhapsody	: 7.5 
	Login		: kbe
	Component	: DefaultComponent 
	Configuration 	: CodeConfig
	Model Element	: PatientEvent
//!	Generated Date	: Thu, 13, Sep 2012  
	File Path	: DefaultComponent\CodeConfig\PatientEvent.cpp
*********************************************************************/

//## auto_generated
#include "PatientEvent.h"
//## auto_generated
#include "Reactor.h"
//## package Default

//## class PatientEvent
PatientEvent::PatientEvent(Reactor * reactor, HANDLE h) {
    //#[ operation PatientEvent(Reactor *,HANDLE)
    handle = h;
    itsReactor = reactor;
	strcpy(buffer_, "empty");
    //#]
}

PatientEvent::PatientEvent() {
}

PatientEvent::PatientEvent(Reactor* reactor, SOCK_Stream *stream) : peer_stream_(stream) {
    //#[ operation LogEvent(Reactor*,SOCK_Stream)
	handle = (HANDLE)stream->get_handle();
    itsReactor = reactor;
	itsReactor->registerHandler(*this, READ_EVENT);
    //#]
}


PatientEvent::~PatientEvent() {
}

void PatientEvent::handleEvent(HANDLE h, Event_Type& et) {
    //#[ operation handleEvent(HANDLE,Event_Type)
	if (et == type) {
		int n = peer_stream_->recv_n(buffer_, sizeof(buffer_), 0);
		if (n > 0) { 
			PatientAction();
		}
		else 
		{
			itsReactor->removeHandler(*this, type);
			delete this; // Deallocate ourselves
		}
	}
    //#]
}

void PatientEvent::PatientAction() {
    //#[ operation PatientAction()
	printf("Patient: %s\n", buffer_);
    //#]
}

/*********************************************************************
	File Path	: DefaultComponent\CodeConfig\PatientEvent.cpp
*********************************************************************/
